/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.cabinetpermission.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.cabinetpermission.entity.BizCabinetPermission;
import vip.xiaonuo.biz.modular.cabinetpermission.param.*;
import vip.xiaonuo.biz.modular.cabinetpermission.service.BizCabinetPermissionService;
import vip.xiaonuo.biz.modular.cabinetpermission.vo.BizCabinetDoorPermissionResp;
import vip.xiaonuo.biz.modular.cabinetpermission.vo.BizCabinetPermissionResp;
import vip.xiaonuo.biz.modular.certification.result.CertificationVO;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 柜门权限控制器-试剂
 *
 * @author kongxm
 * @date 2022/11/20 17:04
 */
@Api(tags = "柜门权限控制器")
@ApiSupport(author = "SNOWY_TEAM", order = 1)
@RestController
@RequestMapping("/biz/cabinetpermission/reagent")
@Validated
public class BizCabinetPermissionReagentController {

    @Resource
    private BizCabinetPermissionService bizCabinetPermissionService;

    /**
     * 获取柜门权限分页
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取柜门权限分页")
    @GetMapping("/page")
    public CommonResult<Page<BizCabinetPermissionResp>> page(BizCabinetPermissionPageParam bizCabinetPermissionPageParam) {
        bizCabinetPermissionPageParam.setCabinetPermissionType(1);
        return CommonResult.data(bizCabinetPermissionService.page(bizCabinetPermissionPageParam));
    }

    /**
     * 添加柜门权限
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加柜门权限")
    @CommonLog("添加柜门权限")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid BizCabinetPermissionAddParam bizCabinetPermissionAddParam) {
        bizCabinetPermissionAddParam.setCabinetPermissionType(1);
        bizCabinetPermissionService.add(bizCabinetPermissionAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑柜门权限
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑柜门权限")
    @CommonLog("编辑柜门权限")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizCabinetPermissionEditParam bizCabinetPermissionEditParam) {
        bizCabinetPermissionService.edit(bizCabinetPermissionEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除柜门权限
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除柜门权限")
    @CommonLog("删除柜门权限")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                               CommonValidList<BizCabinetPermissionIdParam> bizCabinetPermissionIdParamList) {
        bizCabinetPermissionService.delete(bizCabinetPermissionIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取柜门权限详情
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取柜门权限详情")
    @GetMapping("/detail")
    public CommonResult<BizCabinetPermission> detail(@Valid BizCabinetPermissionIdParam bizCabinetPermissionIdParam) {
        return CommonResult.data(bizCabinetPermissionService.detail(bizCabinetPermissionIdParam));
    }

    /**
     * 授权
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("授权")
    @PostMapping("/authorize")
    public CommonResult<String> authorize(@RequestBody @Valid BizCabinetPermissionAuthorizeParam param) {
        bizCabinetPermissionService.authorize(param);
        return CommonResult.ok();
    }

    /**
     * 批量授权
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("批量授权")
    @PostMapping("/authorize/batch")
    public CommonResult<String> batchAuthorize(@RequestBody @Valid BizCabinetPermissionAuthorizeBatchParam param) {
        bizCabinetPermissionService.batchAuthorize(param);
        return CommonResult.ok();
    }

    /**
     * 批量选择用户授权
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 8)
    @ApiOperation("批量授权")
    @PostMapping("/authorize/batch/users")
    public CommonResult<String> batchAuthorizeUsers(@RequestBody @Valid BizCabinetPermissionAuthorizeBatchUsersParam param) {
        param.setCabinetPermissionType(1);
        bizCabinetPermissionService.batchAuthorizeUsers(param);
        return CommonResult.ok();
    }

    /**
     * 拒绝
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 9)
    @ApiOperation("拒绝")
    @PostMapping("/refuse")
    public CommonResult<String> refuse(@RequestBody @Valid BizCabinetPermissionRefuseParam param) {
        bizCabinetPermissionService.refuse(param);
        return CommonResult.ok();
    }

    /**
     * 冻结
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 10)
    @ApiOperation("冻结")
    @PostMapping("/freeze")
    public CommonResult<String> freeze(@RequestBody @Valid BizCabinetPermissionFreezeParam param) {
        bizCabinetPermissionService.freeze(param);
        return CommonResult.ok();
    }

    /**
     * 批量冻结用户
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 11)
    @ApiOperation("批量冻结用户")
    @PostMapping("/freeze/batch/users")
    public CommonResult<String> batchFreezeUsers(@RequestBody @Valid BizCabinetPermissionFreezeBatchUsersParam param) {
        param.setCabinetPermissionType(1);
        bizCabinetPermissionService.batchFreezeUsers(param);
        return CommonResult.ok();
    }

    /**
     * 解冻
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 12)
    @ApiOperation("解冻")
    @PostMapping("/unfreeze")
    public CommonResult<String> unfreeze(@RequestBody @Valid BizCabinetPermissionUnfreezeParam param) {
        bizCabinetPermissionService.unfreeze(param);
        return CommonResult.ok();
    }

    /**
     * 批量拒绝
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 13)
    @ApiOperation("批量拒绝")
    @PostMapping("/refuse/batch")
    public CommonResult<String> batchRefuse(@RequestBody @Valid BizCabinetPermissionRefuseBatchParam param) {
        bizCabinetPermissionService.batchRefuse(param);
        return CommonResult.ok();
    }

    /**
     * 根据柜门获取权限
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 14)
    @ApiOperation("获取柜门权限分页")
    @GetMapping("/list_permission")
    public CommonResult<BizCabinetDoorPermissionResp> listByDoorId(BizCabinetPermissionListParam param) {
        return CommonResult.data(bizCabinetPermissionService.listPermission(param));
    }

    /**
     * 获取证书
     *
     * @author kongxm
     * @date 2022/11/20 17:04
     */
    @ApiOperationSupport(order = 15)
    @ApiOperation("获取柜门权限分页")
    @GetMapping("/certification")
    public CommonResult<List<CertificationVO>> listCertification(String userId) {
        return CommonResult.data(bizCabinetPermissionService.listCertification(userId));
    }
}
